package spem.process.diagram.part;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.gef.Tool;
import org.eclipse.gef.palette.PaletteContainer;
import org.eclipse.gef.palette.PaletteGroup;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.PaletteStack;
import org.eclipse.gef.palette.ToolEntry;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeConnectionTool;
import org.eclipse.gmf.runtime.diagram.ui.tools.UnspecifiedTypeCreationTool;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;

import spem.process.diagram.providers.SpemElementTypes;

/**
 * @generated
 */
public class SpemPaletteFactory {

	/**
	 * @generated
	 */
	public void fillPalette(PaletteRoot paletteRoot) {
		paletteRoot.add(createNode1Group());
		paletteRoot.add(createflow2Group());
	}

	/**
	 * Creates "node" palette tool group
	 * @generated
	 */
	private PaletteContainer createNode1Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.Node1Group_title);
		paletteContainer.setId("createNode1Group"); //$NON-NLS-1$
		paletteContainer.setDescription(Messages.Node1Group_desc);
		paletteContainer.add(createActivity1CreationTool());
		paletteContainer.add(createIteration2CreationTool());
		paletteContainer.add(createStart3CreationTool());
		paletteContainer.add(createDecision4CreationTool());
		paletteContainer.add(new PaletteSeparator());
		paletteContainer.add(createPhase6CreationTool());
		return paletteContainer;
	}

	/**
	 * Creates " flow" palette tool group
	 * @generated
	 */
	private PaletteContainer createflow2Group() {
		PaletteGroup paletteContainer = new PaletteGroup(
				Messages.flow2Group_title);
		paletteContainer.setId("createflow2Group"); //$NON-NLS-1$
		paletteContainer.setDescription(Messages.flow2Group_desc);
		paletteContainer.add(createControlLink1Group());
		return paletteContainer;
	}

	/**
	 * Creates "ControlLink" palette tool group
	 * @generated
	 */
	private PaletteContainer createControlLink1Group() {
		PaletteStack paletteContainer = new PaletteStack(
				Messages.ControlLink1Group_title, null, null);
		paletteContainer.setId("createControlLink1Group"); //$NON-NLS-1$
		paletteContainer.setDescription(Messages.ControlLink1Group_desc);
		paletteContainer.add(createControlFlow1CreationTool());
		paletteContainer.add(createEnd2CreationTool());
		return paletteContainer;
	}

	/**
	 * @generated
	 */
	private ToolEntry createActivity1CreationTool() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(SpemElementTypes.Activity_2003);
		types.add(SpemElementTypes.Activity_3002);
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Activity1CreationTool_title,
				Messages.Activity1CreationTool_desc, types);
		entry.setId("createActivity1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Activity_2003));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createIteration2CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Iteration2CreationTool_title,
				Messages.Iteration2CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Iteration_2002));
		entry.setId("createIteration2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Iteration_2002));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createStart3CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Start3CreationTool_title,
				Messages.Start3CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Start_2005));
		entry.setId("createStart3CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Start_2005));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createDecision4CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Decision4CreationTool_title,
				Messages.Decision4CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Decision_2006));
		entry.setId("createDecision4CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Decision_2006));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createPhase6CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.Phase6CreationTool_title,
				Messages.Phase6CreationTool_desc,
				Collections.singletonList(SpemElementTypes.Phase_2001));
		entry.setId("createPhase6CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.Phase_2001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createControlFlow1CreationTool() {
		LinkToolEntry entry = new LinkToolEntry(
				Messages.ControlFlow1CreationTool_title,
				Messages.ControlFlow1CreationTool_desc,
				Collections.singletonList(SpemElementTypes.ControlFlow_4001));
		entry.setId("createControlFlow1CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.ControlFlow_4001));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private ToolEntry createEnd2CreationTool() {
		NodeToolEntry entry = new NodeToolEntry(
				Messages.End2CreationTool_title,
				Messages.End2CreationTool_desc,
				Collections.singletonList(SpemElementTypes.End_2004));
		entry.setId("createEnd2CreationTool"); //$NON-NLS-1$
		entry.setSmallIcon(SpemElementTypes
				.getImageDescriptor(SpemElementTypes.End_2004));
		entry.setLargeIcon(entry.getSmallIcon());
		return entry;
	}

	/**
	 * @generated
	 */
	private static class NodeToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> elementTypes;

		/**
		 * @generated
		 */
		private NodeToolEntry(String title, String description,
				List<IElementType> elementTypes) {
			super(title, description, null, null);
			this.elementTypes = elementTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeCreationTool(elementTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}

	/**
	 * @generated
	 */
	private static class LinkToolEntry extends ToolEntry {

		/**
		 * @generated
		 */
		private final List<IElementType> relationshipTypes;

		/**
		 * @generated
		 */
		private LinkToolEntry(String title, String description,
				List<IElementType> relationshipTypes) {
			super(title, description, null, null);
			this.relationshipTypes = relationshipTypes;
		}

		/**
		 * @generated
		 */
		public Tool createTool() {
			Tool tool = new UnspecifiedTypeConnectionTool(relationshipTypes);
			tool.setProperties(getToolProperties());
			return tool;
		}
	}
}
